using Godot;

public partial class Main : Node2D
{
	[Export] public bool usePool = false;
	[Export] public int count = 20;
	public PackedScene iconScene;
	public Label FPS;
	public NodePool iconPool;
	public override void _Ready()
	{
		iconScene = ResourceLoader.Load<PackedScene>("res://Scenes/Icon.tscn");
		FPS = GetNode<Label>("CanvasLayer/FPS");
		iconPool = GetNode<NodePool>("IconPool");
	}

	public override void _Process(double delta)
	{
		FPS.Text = Engine.GetFramesPerSecond().ToString();
	}

	public override void _PhysicsProcess(double delta)
	{
		for (int i = 0; i < count; i++)
		{
			RotationDegrees += 1;
			if (usePool)
			{
				var icon = iconPool.GetNode(iconScene) as Icon;
				icon.GlobalPosition = GlobalPosition;
				icon.Rotation = Rotation;
				if (!icon.isInTree)
				{
					icon.iconPool = iconPool;
					icon.usePool = usePool;
					GetTree().Root.AddChild(icon);
				}
				icon.Init();
			}
			else
			{
				var icon = iconScene.Instantiate() as Icon;
				icon.GlobalPosition = GlobalPosition;
				icon.Rotation = Rotation;
				GetTree().Root.AddChild(icon);
			}
		}
	}
}
